home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / c / agl103p.lha / src / agl / poly.c < prev    next >
C/C++ Source or Header  |  1994-12-08  |  10KB  |  469 lines

  1. /******************************************************************************
  2.  
  3. Copyright © 1994 Jason Weber
  4. All Rights Reserved
  5.  
  6. $Id: poly.c,v 1.2.1.5 1994/12/09 05:29:56 jason Exp $
  7.  
  8. $Log: poly.c,v $
  9.  * Revision 1.2.1.5  1994/12/09  05:29:56  jason
  10.  * uses global screen settings instead of structure
  11.  *
  12.  * Revision 1.2.1.4  1994/11/16  06:25:54  jason
  13.  * adjust for borders
  14.  *
  15.  * Revision 1.2.1.3  1994/09/13  03:51:13  jason
  16.  * PolyDraw() test
  17.  *
  18.  * Revision 1.2.1.2  1994/04/06  02:41:16  jason
  19.  * Back to rectangular clear
  20.  *
  21.  * Revision 1.2.1.1  1994/03/29  05:41:32  jason
  22.  * Added RCS Header
  23.  *
  24.  * Revision 1.2.1.1  2002/03/26  22:04:19  jason
  25.  * Added RCS Header
  26.  *
  27.  * Revision 1.2.1.1  2002/03/26  22:00:51  jason
  28.  * RCS/agl.h,v
  29.  *
  30.  
  31. ******************************************************************************/
  32.  
  33.  
  34. #ifndef NOT_EXTERN
  35. #include"agl.h"
  36. #endif
  37.  
  38. #define POLYLINE        FALSE    /* use PolyDraw() instead of Move(), Draw() */
  39. #define MAX_LINE_VERTS    512        /* max # of lines vertices (2 times max lines) */
  40.  
  41. short LineBuffer[MAX_LINE_VERTS];
  42.  
  43.  
  44. /******************************************************************************
  45. void    recti(long x1,long y1,long x2,long y2)
  46.  
  47. ******************************************************************************/
  48. /*PROTOTYPE*/
  49. void recti(long x1,long y1,long x2,long y2)
  50.     {
  51.     bgnline();
  52.     rectvert((float)x1,(float)y1,(float)x2,(float)y2,TRUE);
  53.     endline();
  54.     }
  55.  
  56.  
  57. /******************************************************************************
  58. void    rectfi(long x1,long y1,long x2,long y2)
  59.  
  60. ******************************************************************************/
  61. /*PROTOTYPE*/
  62. void rectfi(long x1,long y1,long x2,long y2)
  63.     {
  64.     if(OneToOne[CurrentWid])    /* bypass transforms if no effect */
  65.         {
  66.         y1=CurrentHeight-y1-1;
  67.         y2=CurrentHeight-y2-1;
  68.  
  69.         RectFill(DrawRPort,x1,y2,x2,y1);
  70.         return;
  71.         }
  72.  
  73.     bgnpolygon();
  74.     rectvert((float)x1,(float)y1,(float)x2,(float)y2,FALSE);
  75.     endpolygon();
  76.     }
  77.  
  78.  
  79. /******************************************************************************
  80. void    rects(short x1,short y1,short x2,short y2)
  81.  
  82. ******************************************************************************/
  83. /*PROTOTYPE*/
  84. void rects(short x1,short y1,short x2,short y2)
  85.     {
  86.     bgnline();
  87.     rectvert((float)x1,(float)y1,(float)x2,(float)y2,TRUE);
  88.     endline();
  89.     }
  90.  
  91.  
  92. /******************************************************************************
  93. void    rectfs(short x1,short y1,short x2,short y2)
  94.  
  95. ******************************************************************************/
  96. /*PROTOTYPE*/
  97. void rectfs(short x1,short y1,short x2,short y2)
  98.     {
  99.     bgnpolygon();
  100.     rectvert((float)x1,(float)y1,(float)x2,(float)y2,FALSE);
  101.     endpolygon();
  102.     }
  103.  
  104.  
  105. /******************************************************************************
  106. void    rect(float x1,float y1,float x2,float y2)
  107.  
  108. ******************************************************************************/
  109. /*PROTOTYPE*/
  110. void rect(float x1,float y1,float x2,float y2)
  111.     {
  112.     bgnline();
  113.     rectvert(x1,y1,x2,y2,TRUE);
  114.     endline();
  115.     }
  116.  
  117.  
  118. /******************************************************************************
  119. void    rectf(float x1,float y1,float x2,float y2)
  120.  
  121. ******************************************************************************/
  122. /*PROTOTYPE*/
  123. void rectf(float x1,float y1,float x2,float y2)
  124.     {
  125.     bgnpolygon();
  126.     rectvert(x1,y1,x2,y2,FALSE);
  127.     endpolygon();
  128.     }
  129.  
  130.  
  131. /******************************************************************************
  132. void    rectvert(float x1,float y1,float x2,float y2,long line)
  133.  
  134. ******************************************************************************/
  135. /*PROTOTYPE*/
  136. void rectvert(float x1,float y1,float x2,float y2,long line)
  137.     {
  138.     static float vert[4][2];
  139.     short n;
  140.  
  141.     vert[0][0]=x1;
  142.     vert[0][1]=y1;
  143.     vert[1][0]=x2;
  144.     vert[1][1]=y1;
  145.     vert[2][0]=x2;
  146.     vert[2][1]=y2;
  147.     vert[3][0]=x1;
  148.     vert[3][1]=y2;
  149.  
  150.     for(n=0;n<4;n++)
  151.         v2f(vert[n]);
  152.  
  153.     if(line)
  154.         v2f(vert[0]);
  155.     }
  156.  
  157.  
  158. /*******************************************************************************
  159. void    bgnpoint(void)
  160.  
  161. *******************************************************************************/
  162. /*PROTOTYPE*/
  163. void bgnpoint(void)
  164.     {
  165.     if(DrawType)
  166.         GL_error("bgnpoint(): bad command order");
  167.  
  168.     DrawType=GL_POINT;
  169.     }
  170.  
  171.  
  172. /*******************************************************************************
  173. void    endpoint(void)
  174.  
  175. *******************************************************************************/
  176. /*PROTOTYPE*/
  177. void endpoint(void)
  178.     {
  179.     if(DrawType!=GL_POINT)
  180.         GL_error("endpoint(): bad command order");
  181.  
  182.     DrawType=FALSE;
  183.     }
  184.  
  185.  
  186. /*******************************************************************************
  187. void    bgnline(void)
  188.  
  189. *******************************************************************************/
  190. /*PROTOTYPE*/
  191. void bgnline(void)
  192.     {
  193.     if(DrawType)
  194.         GL_error("bgnline(): bad command order");
  195.  
  196.     DrawType=GL_LINE;
  197.     BgnLine=TRUE;
  198.     Verts=0;
  199.     }
  200.  
  201.  
  202. /*******************************************************************************
  203. void    endline(void)
  204.  
  205. *******************************************************************************/
  206. /*PROTOTYPE*/
  207. void endline(void)
  208.     {
  209.     if(DrawType!=GL_LINE)
  210.         GL_error("endline(): bad command order");
  211.  
  212. #if POLYLINE
  213.  
  214.     else
  215.         PolyDraw(DrawRPort,Verts/2,LineBuffer);
  216.  
  217. #endif
  218.  
  219.     DrawType=FALSE;
  220.     }
  221.  
  222.  
  223. /*******************************************************************************
  224. void    bgnpolygon(void)
  225.  
  226. *******************************************************************************/
  227. /*PROTOTYPE*/
  228. void bgnpolygon(void)
  229.     {
  230.     if(DrawType)
  231.         GL_error("bgnpolygon(): bad command order");
  232.  
  233.     DrawType=GL_POLYGON;
  234.     Verts=0;
  235.     }
  236.  
  237.  
  238. /*******************************************************************************
  239. void    endpolygon(void)
  240.  
  241. *******************************************************************************/
  242. /*PROTOTYPE*/
  243. void endpolygon(void)
  244.     {
  245.     if(DrawType!=GL_POLYGON)
  246.         GL_error("endpolygon(): bad command order");
  247.  
  248.     AreaEnd(DrawRPort);
  249.  
  250.     DrawType=FALSE;
  251.     }
  252.  
  253.  
  254. /*******************************************************************************
  255. void    render_vertex(short vert[2])
  256.  
  257. *******************************************************************************/
  258. /*PROTOTYPE*/
  259. void render_vertex(short vert[2])
  260.     {
  261.     long x,y;
  262.  
  263.     x=vert[0];
  264.     y=CurrentHeight-vert[1]-1;
  265.  
  266.     if(Bordered[CurrentWid])
  267.         {
  268.         x+=BorderWidth;
  269.         y+=BorderWidth+BorderHeight;
  270.         }
  271.  
  272.     switch(DrawType)
  273.         {
  274.         case FALSE:
  275.             GL_error("v??(): bad command order");
  276.             break;
  277.  
  278.         case GL_POINT:
  279.             WritePixel(DrawRPort,x,y);
  280.             break;
  281.  
  282.         case GL_LINE:
  283. #if POLYLINE
  284.             if(Verts==MAX_LINE_VERTS)
  285.                 GL_error("Exceeded max points in polyline");
  286.             else
  287.                 {
  288.                 LineBuffer[Verts++]=x;
  289.                 LineBuffer[Verts++]=y;
  290.                 }
  291. #else
  292.             if(BgnLine)
  293.                 {
  294.                 BgnLine=FALSE;
  295.                 Move(DrawRPort,x,y);
  296.                 }
  297.             else
  298.                 Draw(DrawRPort,x,y);
  299. #endif
  300.             break;
  301.  
  302.         case GL_POLYGON:
  303.             if(Verts==MAX_POLY_VERTS)
  304.                 GL_error("Exceeded max points in polygon");
  305.             else
  306.                 {
  307.                 if(Verts)
  308.                     AreaDraw(DrawRPort,x,y);
  309.                 else
  310.                     AreaMove(DrawRPort,x,y);
  311.  
  312.                 Verts++;
  313.                 }
  314.             break;
  315.         }
  316.     }
  317.  
  318.  
  319. /******************************************************************************
  320. void    mapcolor(long m,long r,long g,long b)
  321.  
  322.     maintain 256 shade standard
  323. ******************************************************************************/
  324. /*PROTOTYPE*/
  325. void mapcolor(long m,long r,long g,long b)
  326.     {
  327.     char string[100];
  328.  
  329.     if(m<0 || m>15)
  330.         {
  331.         sprintf(string,"mapcolor(): bad index %d",m);
  332.         GL_error(string);
  333.         return;
  334.         }
  335.  
  336.     r=(r+7)/16;
  337.     g=(g+7)/16;
  338.     b=(b+7)/16;
  339.  
  340.     ColorMap[m]= (((r<<4)+g)<<4)+b;
  341.     SetRGB4(GLView,m,r,g,b);
  342.     }
  343.  
  344.  
  345. /******************************************************************************
  346. void    getmcolor(long m,long *r,long *g,long *b)
  347.  
  348. ******************************************************************************/
  349. /*PROTOTYPE*/
  350. void getmcolor(long m,long *r,long *g,long *b)
  351.     {
  352.     *r=ColorMap[m];
  353.  
  354.     *b= *r&15;
  355.     *r= *r>>4;
  356.     *g= *r&15;
  357.     *r= *r>>4;
  358.  
  359.     *r *=16;
  360.     *g *=16;
  361.     *b *=16;
  362.     }
  363.  
  364.  
  365. /*******************************************************************************
  366. void    color(long c)
  367.  
  368. *******************************************************************************/
  369. /*PROTOTYPE*/
  370. void color(long c)
  371.     {
  372.     CurrentColor=c;
  373.     SetAPen(DrawRPort,c);
  374.     }
  375.  
  376.  
  377. /*******************************************************************************
  378. long    getcolor(void)
  379.  
  380. *******************************************************************************/
  381. /*PROTOTYPE*/
  382. long getcolor(void)
  383.     {
  384.     return CurrentColor;
  385.     }
  386.  
  387.  
  388. /*******************************************************************************
  389. void    clear(void)
  390.  
  391. *******************************************************************************/
  392. /*PROTOTYPE*/
  393. void clear(void)
  394.     {
  395.     long bit,value;
  396.     long m,line,screenwidth,offset,lineoff;
  397.     size_t linewidth;
  398.     PLANEPTR planes,planem;
  399.  
  400.     /* only activate one of the following three methods */
  401.  
  402.  
  403. #if FALSE
  404.  
  405.     /* clear window */
  406.     RectFill(DrawRPort,0,0,CurrentWidth-1,CurrentHeight-1);
  407.  
  408. #endif
  409.  
  410.  
  411. #if TRUE
  412.  
  413.     /* clear whole screen (clipped to window) */
  414.     SetRast(DrawRPort,CurrentColor);
  415.  
  416. #endif
  417.  
  418.  
  419. #if FALSE
  420.     size=ScreenWidth*ScreenHeight/8;
  421.  
  422.     /* individually clear each full plane */
  423.     for(m=0;m<ScreenDeep;m++)
  424.         memset(DrawRPort->BitMap->Planes[m],2<<m,size);
  425.  
  426. #endif
  427.  
  428.  
  429. #if FALSE
  430.  
  431.     screenwidth=ScreenWidth/8+1;
  432.     offset=screenwidth*(ScreenHeight-CurrentPosY-CurrentHeight-1)+CurrentPosX/8;
  433.     linewidth=(CurrentWidth+7)/8+1;
  434.     bit=1;
  435.  
  436.     if(offset)
  437.         {
  438.         offset--;
  439.         linewidth++;
  440.         }
  441.  
  442.     /* individually clear area in each plane */
  443.     for(m=0;m<ScreenDeep;m++)
  444.         {
  445.         if(CurrentColor&bit)
  446.             value=255;
  447.         else
  448.             value=0;
  449.  
  450.         lineoff=offset;
  451.         planem= (DrawRPort->BitMap->Planes[m]);
  452.  
  453.         for(line=0;line<CurrentHeight;line++)
  454.             {
  455.             memset(&(planem[lineoff]),value,linewidth);
  456.  
  457.             lineoff+=screenwidth;
  458.             }
  459.  
  460.         bit<<=1;
  461.         }
  462.  
  463. /*
  464.         BltClear((DrawRPort->BitMap->Planes[m])+offset,size,0);
  465. */
  466.  
  467. #endif
  468.     }
  469.